package com.ohimy.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 * 用户登录信息封装类
 * 
 * @author Tony Tang
 * @version 1.0
 */
@Entity
@MappedSuperclass
@Table(name = "ohimy_user")
public class User implements Serializable {

	private static final long serialVersionUID = -1983881057708786520L;

	private long id;

	private String email; // 用户名(通行证账号)作为帐号

	private String password; // 密码

	private String nick; // 昵称

	private String header; // 头像地址

	private int score; // 用户积分

	private int right; // 权限值

	private Date created; // 创建时间

	private Date last_visit; // 最后访问时间

	private UserDetail userDetail; // 用户基本信息外键

	private long fnumber; // 朋友人数(不映射入数据库)

	private long gnumber;// 参加群组个数(不映射入数据库)

	private List<GroupUserShip> groupUserShip;

	private List<UserFriendShip> userFriendShip;

	private List<Forum> forum;

	private List<ForumBody> forumBody;
	
	private List<InfoItemComment> infoItemComment;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@Column(name = "_email", length = 64, unique = true)
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "_password", length = 32)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "_right")
	public int getRight() {
		return right;
	}

	public void setRight(int right) {
		this.right = right;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "_created", updatable = false)
	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	@Column(name = "_nick", length = 16)
	public String getNick() {
		return nick;
	}

	public void setNick(String nick) {
		this.nick = nick;
	}

	@Column(name = "_header", length = 32)
	public String getHeader() {
		return header;
	}

	public void setHeader(String header) {
		this.header = header;
	}

	@Column(name = "_score", length = 32)
	public int getScore() {
		return score;
	}

	public void setScore(int score) {
		this.score = score;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "_last_visit")
	public Date getLast_visit() {
		return last_visit;
	}

	public void setLast_visit(Date last_visit) {
		this.last_visit = last_visit;
	}

	@OneToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
	@PrimaryKeyJoinColumn
	public UserDetail getUserDetail() {
		return userDetail;
	}

	public void setUserDetail(UserDetail userDetail) {
		this.userDetail = userDetail;
	}

	@Transient
	public long getFnumber() {
		return fnumber;
	}

	public void setFnumber(long fnumber) {
		this.fnumber = fnumber;
	}

	@Transient
	public long getGnumber() {
		return gnumber;
	}

	public void setGnumber(long gnumber) {
		this.gnumber = gnumber;
	}

	@OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
	public List<GroupUserShip> getGroupUserShip() {
		return groupUserShip;
	}

	public void setGroupUserShip(List<GroupUserShip> groupUserShip) {
		this.groupUserShip = groupUserShip;
	}

	@OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
	public List<UserFriendShip> getUserFriendShip() {
		return userFriendShip;
	}

	public void setUserFriendShip(List<UserFriendShip> userFriendShip) {
		this.userFriendShip = userFriendShip;
	}

	@OneToMany(mappedBy = "publisher", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
	public List<Forum> getForum() {
		return forum;
	}

	public void setForum(List<Forum> forum) {
		this.forum = forum;
	}

	@OneToMany(mappedBy = "applier", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
	public List<ForumBody> getForumBody() {
		return forumBody;
	}

	public void setForumBody(List<ForumBody> forumBody) {
		this.forumBody = forumBody;
	}

	@OneToMany(mappedBy = "replier", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
	public List<InfoItemComment> getInfoItemComment() {
		return infoItemComment;
	}

	public void setInfoItemComment(List<InfoItemComment> infoItemComment) {
		this.infoItemComment = infoItemComment;
	}

}
